import request from '@/utils/request'

const cellStyle = ({ colDef, value }: any) => {
  return {
    background: '#f5f7f7'
  }
}

export const isPreviousLine = (tableDate:any, field:string, rowIndex:number) => {
  return tableDate.map((item:any, idx:number):any => {
    if(idx === rowIndex - 1){
      return item[field]
    }
    return null
  })
}

// 查询列表
export function queryTableData() {
  return request({
    url: '/funConfig/situation/getOeeContinuousMachineSituationList',
    method: 'get'
  })
}

// 修改列表
export function editTableData(data:any) {
  return request({
    url: '/funConfig/situation',
    method: 'put',
    data: data
  })
}

// 修改例外无 optinos
export function getEditOptions(query:any) {
  return request({
    url: '/SYSConfig/machineType/list',
    method: 'get',
    params: query
  })
}

const cellRendererLossName = ({ data, value }:any) => {
  return `<div style="margin-top: 18px"}}> ${value}</div>`
}

const cellRendererEptStatus = ({ value, data }:any) => {
  if(data.eptStatus === 'RUN' || (data.eptStatus === 'PM' && data.lossName === '计划缺失')){
    return `<div style="margin-top: 18px"}}> ${value}</div>`
  } else if(data.eptStatus === 'IDLE'){
    return `<div style="margin-top: 48px"}}> ${value}</div>`
  } else if(data.eptStatus === 'DOWN'){
    return `<div style="margin-top: 80px"}}> ${value}</div>`
  } else if(data.eptStatus === 'PM'){
    return `<div style="margin-top: 340px"}}> ${value}</div>`
  }
}

const cellRenderer = ({ value }:any) => {
  if(value === 'default'){
    return null
  }
  return value
}

export const column = [
  {
    headerName: "下一状态",
    children: [
        {
          headerName: '现状态',
          children: [
            // { headerName: "", field: "siteId", checkboxSelection: true, width: 20, cellStyle },
            { headerName: "流失名", field: "lossName", width: 80, cellStyle, cellRenderer: cellRendererLossName, pinned: 'left' },
            { headerName: "EPT状态", field: "eptStatus", width: 80, cellStyle, cellRenderer: cellRendererEptStatus, pinned: 'left' }
          ]
        }
    ]
  },

  {
    headerName: "流失名",  children: [
        {
          headerName: 'EPT状态',
          children: [
            { headerName: "R_Code", field: "rCode", width: 80, cellStyle, cellRenderer: cellRendererLossName, pinned: 'left' }
          ]
        }
      ]
  },
  {
    headerName: "正在生产",  children: [
        {
          headerName: 'RUN',
          children: [
            { headerName: "1000", field: "runOne", minWidth: 80, flex: 1, cellRenderer, tooltipField:'runOne' }
          ]
        }
      ]
  },
  {
    headerName: "投入待料",  children: [
        {
          headerName: 'IDLE',
          children: [
            { headerName: "1100", field: "idelOne", minWidth: 80, flex: 1, cellRenderer, tooltipField:'idelOne' }
          ]
        }
      ]
  },
  {
    headerName: "排出堵料",  children: [
        {
          headerName: 'IDLE',
          children: [
            { headerName: "1200", field: "idelTwo", minWidth: 80, flex: 1, cellRenderer, tooltipField:'idelTwo' }
          ]
        }
      ]
  },
  {
    headerName: "计划缺失",  children: [
        {
          headerName: 'IDLE',
          children: [
            { headerName: "1300", field: "idelThree", minWidth: 80, flex: 1, cellRenderer, tooltipField:'idelThree' }
          ]
        }
      ]
  },
  {
    headerName: "设备故障",  children: [
        {
          headerName: 'DOWN',
          children: [
            { headerName: "2***", field: "downOne", minWidth: 80, flex: 1, cellRenderer, tooltipField:'downOne' }
          ]
        }
      ]
  },
  {
    headerName: "Interlock",  children: [
        {
          headerName: 'DOWN',
          children: [
            { headerName: "3000", field: "downTwo", minWidth: 80, flex: 1, cellRenderer, tooltipField:'downTwo' }
          ]
        }
      ]
  },
  {
    headerName: "原/辅料故障",  children: [
        {
          headerName: 'DOWN',
          children: [
            { headerName: "4***", field: "downThree", minWidth: 80, flex: 1, cellRenderer, tooltipField:'downThree' }
          ]
        }
      ]
  },
  {
    headerName: "一级保养",  children: [
        {
          headerName: 'PM',
          children: [
            { headerName: "5100", field: "pmOne", minWidth: 80, flex: 1, cellRenderer, tooltipField:'pmOne' }
          ]
        }
      ]
  },
  {
    headerName: "定期保养",  children: [
        {
          headerName: 'PM',
          children: [
            { headerName: "5200", field: "pmTwo", minWidth: 80, flex: 1, cellRenderer, tooltipField:'pmTwo' }
          ]
        }
      ]
  },
  {
    headerName: "设备非定期",  children: [
        {
          headerName: 'PM',
          children: [
            { headerName: "6100", field: "pmThree", minWidth: 80, flex: 1, cellRenderer, tooltipField:'pmThree' }
          ]
        }
      ]
  },
  {
    headerName: "生产5S",  children: [
        {
          headerName: 'PM',
          children: [
            { headerName: "6111", field: "pmFour", minWidth: 80, flex: 1, cellRenderer, tooltipField:'pmFour' }
          ]
        }
      ]
  },
  {
    headerName: "报警应急",  children: [
        {
          headerName: 'PM',
          children: [
            { headerName: "6112", field: "pmFive", minWidth: 80, flex: 1, cellRenderer, tooltipField:'pmFive' }
          ]
        }
      ]
  },
  {
    headerName: "品质非定期",  children: [
        {
          headerName: 'PM',
          children: [
            { headerName: "6200", field: "pmSix", minWidth: 80, flex: 1, cellRenderer, tooltipField:'pmSix' }
          ]
        }
      ]
  },
  {
    headerName: "实验借机",  children: [
        {
          headerName: 'PM',
          children: [
            { headerName: "7000", field: "pmSeven", minWidth: 80, flex: 1, cellRenderer, tooltipField:'pmSeven' }
          ]
        }
      ]
  },
  {
    headerName: "改造改善",  children: [
        {
          headerName: 'PM',
          children: [
            { headerName: "8000", field: "pmEight", minWidth: 80, flex: 1, cellRenderer, tooltipField:'pmEight' }
          ]
        }
      ]
  },
  {
    headerName: "辅材料更换",  children: [
        {
          headerName: 'PM',
          children: [
            { headerName: "9100", field: "pmNine", minWidth: 80, flex: 1, cellRenderer, tooltipField:'pmNine' }
          ]
        }
      ]
  },
  {
    headerName: "版型变更",  children: [
        {
          headerName: 'PM',
          children: [
            { headerName: "9200", field: "pmTen", minWidth: 80, flex: 1, cellRenderer, tooltipField:'pmTen' }
          ]
        }
      ]
  },
  {
    headerName: "未知PM",  children: [
        {
          headerName: 'PM',
          children: [
            { headerName: "10000", field: "pmEleven", minWidth: 80, flex: 1, cellRenderer, tooltipField:'pmEleven' }
          ]
        }
      ]
  },
  { headerName: "备注", field: "remark", minWidth: 300, flex: 1, tooltipField:'remark' }
]